<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<script type="text/javascript" src="${ctx}/static/tools/jquery-validationEngine/jquery.validationEngine.js"></script>
		<script type="text/javascript" src="${ctx}/static/tools/jquery-validationEngine/jquery.validationEngine-cn.js"></script>
	</head>
	

	<body>
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
	
			<ul class="breadcrumb">
				<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
				<li>用户中心</li>
				<li class="active">班级管理</li>
			</ul>
			<!-- .breadcrumb -->
		</div>	
		
		<div class="page-content">
			<div class="page-header">
				<h1>班级管理
					<small>
					<i class="icon-double-angle-right"></i>
					查看
					</small>					
				</h1>			
			</div>
			<div>
				<form  id="searchForm" name="searchForm" role="form" method="post" action="${ctx}/sys/tclass/list">
					<input type="text" id="name" name="name" placeholder="班级名称" value="${searchForm.name}" class="col-xs-10 col-sm-2"/>
					<label for="form-field-select-3" style="width:40px;margin-left: 20px" for="schoolId">学校 </label>
					<select  id=schoolId name="schoolId" data-placeholder="请选择学校" onchange="javascript:changeSchool();">
						<option value="">请选择</option>
					</select>
					<label for="form-field-select-3" style="width:40px;margin-left: 20px" for="gradeId">年级 </label>
					<select  id=gradeId name="gradeId" data-placeholder="请选择年级">
						<option value="">请选择</option>
					</select>
					<input id="sysSchoolListSearch" type="submit" value="查询" style="margin-left: 10px">
				</form>				
			</div>
				
			<div style="line-height: 10px;">&nbsp;</div> 
		
			<div class="row" >	
			<div class="col-xs-12">
				<table id="simple-table" class="table table-striped table-bordered table-hover"  style="margin-top:5px;">
							<thead>
								<tr>
									<th class="center" style="width: 30px;">
										<label><input class="ace" type="checkbox" id="zcheckbox" /><span class="lbl"></span></label>
									</th>
									<th class='center' style="width:50px;">序号</th>

									<th class="center">班级名称</th>
									<th class="center">学校</th>
									<th class="center">年级</th>
									<th class="center">创建时间</th>
									<th class="center" >操作</th>

								</tr>
							</thead>
												
							<tbody id="userlist">
							<c:forEach var="res" items="${res.data.rows}" varStatus="status">
							<tr id="userinfo_row_${res.id}" >
								<td class="center">
									<label><input type="checkbox" class="ace" /><span class="lbl"></span></label>
								</td>	
								<td class='center' >${status.index+1}</td>  							
								<td class="center">&nbsp;<a style="margin-left: 3%;" href="${ctx}/sys/tclass/toUpdate/${res.id}" title="">${res.name}</a></td>
								<td class="center">&nbsp;${res.schoolName}</td>
								<td class="center">&nbsp;${res.gradeName}</td>
								 <td class="center" title="${res.createTime}">&nbsp;<fmt:formatDate value="${res.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
								 
				                 <td class="center">
				                 	<button title="编辑" class="btn btn-xs btn-info" onclick="location='${ctx}/sys/tclass/toUpdate/${res.id}'">
										<i class="icon-edit bigger-120"></i>
									</button>
								</td>
							</tr> 
							</c:forEach>
							</tbody>
				</table>
				<div style="margin-bottom: 20px">
					<a class="btn btn-sm btn-success" href="${ctx}/sys/tclass/toAdd">新增</a>
				</div>	
				
				<%@ include file="/WEB-INF/views/decorators/page.jsp"%> 	 
			</div>
			</div>
			
			
		</div>
		<script type="text/javascript">
			jQuery(function($) {
				$('table th input:checkbox').on('click' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
						
				});
				/* $('.date-picker').datepicker({autoclose:true}).next().on(ace.click_event, function(){
					$(this).prev().focus();
				}); */
			})
			
			$(function(){
				var schoolId = "${searchForm.schoolId}";
				var gradeId = "${searchForm.gradeId}";
				$.ajax({
					async: true,
					type:"POST",
					data:null,
					url: "${ctx}/sys/tschool/listall",
					dataType: "json",
					success: function (data) {
						if("success" == data.result){//成功
							if(data.list.length>0){
								for(var a=0;a<data.list.length;a++){
									if(schoolId!='' && schoolId == data.list[a].id ){
										$("#schoolId").append("<option selected = 'selected' value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
									}else{
										$("#schoolId").append("<option value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
									}
								}
							}
					    }else{//失败
					    	 alert("学校加载失败");
					    }
					}
				},"json");
				if(schoolId!=null && schoolId!=""){
					var obj = new Object();
					obj.schoolId= schoolId;
					$.ajax({
					    async: true,
					    type:"POST",
					    data:obj,
					    url: "${ctx}/sys/tgrade/findgradeBySchoolId",
					    dataType: "json",
					    success: function (data) {
					    	if("success" == data.result){//成功
								if(data.list.length>0){
									for(var a=0;a<data.list.length;a++){
										if(gradeId!=null && gradeId!='' && gradeId == data.list[a].id ){
											$("#gradeId").append("<option selected = 'selected' value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}else{
											$("#gradeId").append("<option value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}
									}
								}
						    }else{//失败
						    	alert("年级加载失败");
						    }
					    }
					},"json");
				}
			});
			function changeSchool(){
				var schoolId =$("#schoolId").val();
				clearGrade();
				var obj = new Object();
				obj.schoolId= schoolId;
				if(schoolId!=null && schoolId!=""){
					$.ajax({
				        async: true,
				        type:"POST",
				        data:obj,
				        url: "${ctx}/sys/tgrade/findgradeBySchoolId",
				        dataType: "json",
				        success: function (data) {
				    	    if("success" == data.result){//成功
								if(data.list.length>0){
									for(var a=0;a<data.list.length;a++){
										$("#gradeId").append("<option value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
									}
								}else{
								}
				    	    }else{//失败
				    	    	alert("年级加载失败");
				    	    }
				        }
					},"json");
				}
			}
			function clearGrade(){
				$("#gradeId").val("");
				$("#gradeId").html("");
				$("#gradeId").append("<option  value=''>请选择</option>");
			}
		</script>
	</body>

</html>
